package com.example.demo.annotion;

import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @Description AnnotationTest3
 * @Author songchuanlong
 * @Date 2025-06-11
 */
public class AnnotationTest3 {
    @Test
    public void testClass(){
        //1、先得到class对象
        Class c = Demo.class;
        //2、解析类上的注解
        if(c.isAnnotationPresent(MyTest4.class)){
            MyTest4 myTest4 = (MyTest4) c.getDeclaredAnnotation(MyTest4.class);
            System.out.println(myTest4.aaa());
            System.out.println(myTest4.value());
            System.out.println(Arrays.toString(myTest4.bbb()));
        }else {
            System.out.println("没有该注解!");
        }
    }



    @Test
    public void tesMethod() throws Exception {
        //1、先得到class对象
        Class c = Demo.class;
        Method testA = c.getDeclaredMethod("testA");
        //2、解析类上的注解
        if(testA.isAnnotationPresent(MyTest4.class)){
            MyTest4 myTest4 = (MyTest4) testA.getDeclaredAnnotation(MyTest4.class);
            System.out.println(myTest4.aaa());
            System.out.println(myTest4.value());
            System.out.println(Arrays.toString(myTest4.bbb()));
        }else {
            System.out.println("没有该注解!");
        }
    }
}
